package ui.activity.order.biz;

import Bean.AddOrderBean;
import Bean.FindAddressBean;
import base.BaseBiz;
import base.BaseResp;
import coom.BaseSubscribe;
import coom.RetrofitHelp;
import okhttp3.RequestBody;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import ui.activity.poscontrol.beanmodel.RedBallnumBean;

/**
 * Created by chenjian on 19/2/26.
 * 1
 */

public class ConfirmOrderBiz extends BaseBiz {


    /**
     * 获取地址列表列表
     */
    public void getAddressList(RequestBody requestBody, final Callback<FindAddressBean.DataBean> callback) {
        com.add(RetrofitHelp.getSecretApi().findAddressBuCustomId(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<FindAddressBean.DataBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((FindAddressBean.DataBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((FindAddressBean.DataBean) obj);
                    }
                })
        );
    }

    /**
     * 下单 pos
     */
    public void addOrder(RequestBody requestBody, final Callback<AddOrderBean.DataBean> callback) {
        com.add(RetrofitHelp.getSecretApi().addOrder(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<AddOrderBean.DataBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((AddOrderBean.DataBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((AddOrderBean.DataBean) obj);
                    }
                })
        );
    }
    /**
     * 下单 物料
     */
    public void addOrder2(RequestBody requestBody, final Callback<AddOrderBean.DataBean> callback) {
        com.add(RetrofitHelp.getSecretApi().addOrdermaterials(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<AddOrderBean.DataBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((AddOrderBean.DataBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((AddOrderBean.DataBean) obj);
                    }
                })
        );
    }
    /**
     * 查询红包数量
     */
    public void queryRedballNum(String id,final Callback<RedBallnumBean> callback) {
        String url = RetrofitHelp.BASE_URL + "api/ticket/model/" + id;
        com.add(RetrofitHelp.getSecretApi().getRedballNum(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<RedBallnumBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((RedBallnumBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((RedBallnumBean) obj);
                    }
                })
        );
    }

}
